package gui.creators;

import events.packageEvents.PackageCreatedEvent;
import events.packageEvents.PackagePickedUpEvent;
import framework.events.Event;
import framework.gui.GUI;
import framework.gui.GUIObject;
import framework.gui.GUIObjectCreator;
import gui.objects.GUIPackage;

public class GUIPackageCreator extends GUIObjectCreator {

	public GUIPackageCreator(GUI gui) {
		super(gui);
	}

	@Override
	protected GUIObject createGUIObject(Event event) {
		if (event instanceof PackageCreatedEvent ) {
			PackageCreatedEvent e = (PackageCreatedEvent) event;
			return new GUIPackage(e.getId(), e.getPosition());
		} else {
			throw new IllegalStateException();
		}
	}

	@Override
	protected Class<? extends Event> getCreationEventClass() {
		return PackageCreatedEvent.class;
	}

	@Override
	protected Class<? extends Event> getDestroyEventClass() {
		return PackagePickedUpEvent.class;
	}

	@Override
	protected GUIObject getDestroyGUIObject(Event event) {
		if (event instanceof PackagePickedUpEvent ) {
			PackagePickedUpEvent e = (PackagePickedUpEvent) event;
			return new GUIPackage(e.getId(), null);
		} else {
			throw new IllegalStateException();
		}
	}
}
